<?php
	include "./include/om_config.inc";
  $smarty = new SmartyWWW();
 
  $filePath = '';
  $fileName = '';
  
  $filePath = "";
  if(isset($_POST['submitBtn']))
  {
    $target_path = 'bhavcopies';
    $target_path = $target_path ."/". basename( $_FILES['fileName']['name']);
    
    $oldfile =  basename($_FILES['fileName']['name']);
    //new file name exmaple for a profile image of a user
    //$newfile = $username . "." . $ext;
    // move the file to the final destination
    //$target_path = $target_path . basename($_FILES['fileName']['name']);
    if(move_uploaded_file($_FILES['fileName']['tmp_name'], $target_path)) 
    {
      $selectGeneral = "SELECT * FROM general";
      $resultGeneral = mysql_query($selectGeneral);
      if($resultGeneral && mysql_num_rows($resultGeneral) == 0)
      {
      	$insertQuery ="INSERT INTO general (filePath,fileName) 
      	               VALUES ('bhavcopies','".$_FILES['fileName']['name']."')";
      	$resultQuery = mysql_query($insertQuery);
      }
      if(mysql_num_rows($resultGeneral) != 0)
      {
      	$updateQuery = "UPDATE general SET filePath='bhavcopies',
                        fileName='".$_FILES['fileName']['name']."'";
      	$updateResult = mysql_query($updateQuery);
    	}
      header("Location: storeBhavCopyMcxNew.php?exc=MCX");
    } 
    else
    {
        echo "There was an error uploading the file, please try again!";
    }    
  }
  
  $selectQuery = "SELECT * FROM general";
  $selectResult = mysql_query($selectQuery);
  if($selectRow = mysql_fetch_array($selectResult))
  {
    $filePath = $selectRow['filePath'];
    $fileName = $selectRow['fileName'];
  }
  $headMenu  = "<B>Tips : &nbsp;&nbsp;</B><A href='./txtFile.php?exc=MCX'>SubmitMcx </A>&nbsp;&nbsp;&nbsp;";

  $smarty->assign("headMenu", $headMenu);
?>
<BODY><br>

<H1><CENTER><FONT color="red">TIPS</FONT></CENTER></H1><HR>

<CENTER>
  <FORM enctype="multipart/form-data" action="txtFileNew.php" name="form1" method="POST">
	<a href="index.php">Home</a>&nbsp;&nbsp;&nbsp;	
	<a href="report.php">Week Report</a>&nbsp;&nbsp;&nbsp;
	<a href="monthReport.php">Month Report</a><BR><BR>
	<input type="hidden" name="exc" value="<? echo  $exchange; ?>">
<INPUT size="60" type="hidden" name="filePath"><BR>
File Name: <INPUT name="fileName" type="file" onChange="document.form1.filePath.value=document.form1.fileName.value;">
<INPUT type="submit" name="submitBtn" value="Submit File"> 
</FORM>
</CENTER>
